package com.itheima.goods.mapper;



import com.github.pagehelper.Page;
import com.itheima.annotation.AutoFill;
import com.itheima.enumeration.OperationType;
import com.itheima.goods.dto.SetmealDTO;
import com.itheima.goods.dto.SetmealPageQueryDTO;
import com.itheima.goods.pojo.Setmeal;
import com.itheima.goods.pojo.SetmealDish;
import com.itheima.goods.vo.SetmealOverViewVO;
import com.itheima.goods.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {
    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */

    Page<SetmealVO> pageSelect(SetmealPageQueryDTO setmealPageQueryDTO);
    /**
     * 套餐起售、停售
     * @param status
     * @param id
     * @return
     */
    @Update("update setmeal set  status=#{status} where id=#{id}")
    void updateStatus(Integer status, Long id);

    /**
     * 新增套餐
     * @param setmeal
     * @return
     */
    @Insert("insert into setmeal(category_id, name, price,status, description, image, create_time, update_time, create_user, update_user)" +
            "values (#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @AutoFill(OperationType.INSERT)
    void add(Setmeal setmeal);

    /**
     * 添加套餐菜品
     * @param setmealDish
     */
    @Insert("insert into setmeal_dish(setmeal_id, dish_id, name, price, copies) " +
            "VALUES(#{setmealId},#{dishId},#{name},#{price},#{copies}) ")
    void addSetmealDish(SetmealDish setmealDish);
    /**
     * 查询套餐返回套餐id
     * @param ids
     * @return
     */
    List<Long> deleteByIds(Long[] ids);

    /**
     * 根据套餐id删除菜品semeal_dish
     * @param deletedId
     */
    @Delete("delete from setmeal_dish where setmeal_id=#{deletedId}")
    void deleteByIdSetmealDish(Long deletedId);
    /**
     * 根据套餐id删除套餐
     * @param ids
     */
    void delete(Long[] ids);

    SetmealDTO findById(Long id);

    @AutoFill(OperationType.UPDATE)
    void updateSetmeal(Setmeal setmeal);

    /**
     * 根据ids，查看状态为起售的套餐有多少个
     * @param ids
     * @return
     */
    Long select(Long[] ids);

    @Select("select * from setmeal where category_id=#{categoryId}")
    List<Setmeal> list(Long categoryId);
    /**
     * 查询套餐总览
     * @return
     */
    SetmealOverViewVO overviewSetmeals();
}
